package net.starwifi.duobao.entity;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/7.
 */
@Entity
@Table(name = "duob_db_share")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "duob_db_share_sequence")
public class DBShare extends BaseEntity {


    /** 产品信息*/
    private Long productId;

    /** 产品信息*/
    private String productName;

    /** 参与次数*/
    private Integer count;

    /** 晒单标题*/
    private String title;

    /** 晒单内容 */
    private String content;

    //** 夺宝期*//*
    private DBTimes dbTimes;

    //** 发布的用户 *//*
    private Member member;

    /** 夺宝商品图片 */
    private List<DBShareImage> dbShareImages = new ArrayList<DBShareImage>();

    /** 是否显示*/
    private Boolean isShow;

    @Valid
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "duob_db_share_image")
    public List<DBShareImage> getDbShareImages() {
        return dbShareImages;
    }

    public void setDbShareImages(List<DBShareImage> dbShareImages) {
        this.dbShareImages = dbShareImages;
    }

    @Column
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @ManyToOne
    @JoinColumn(name = "times_id")
    public DBTimes getDbTimes() {
        return dbTimes;
    }

    public void setDbTimes(DBTimes dbTimes) {
        this.dbTimes = dbTimes;
    }



    @ManyToOne
    @JoinColumn(name = "member_id")
    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }


    @Column
    public Boolean getIsShow() {
        return isShow;
    }

    public void setIsShow(Boolean isShow) {
        this.isShow = isShow;
    }

    @Column
    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    @Column
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @Column
    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    @JsonProperty
    @Transient
    public String getMedium() {
        if (getDbShareImages() != null && !getDbShareImages().isEmpty()) {
            return getDbShareImages().get(0).getMedium();
        }
        return null;
    }


}
